import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:kkhousekeep/page/me/edit_nickname.dart';
import 'package:kkhousekeep/page/me/edit_profile_controller.dart';
import 'package:kkhousekeep/widget/custom_app_bar.dart';
import 'package:kkhousekeep/widget/setting_section.dart';

import '../../widget/dialog/custom_dialog.dart';

class EditProfile extends StatelessWidget {
  const EditProfile({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<EditProfileController>(
        init: EditProfileController(),
        builder: (controller) => Scaffold(
              appBar: CustomAppBar("编辑个人信息"),
              body: Container(
                padding: EdgeInsets.only(top: 32.h),
                color: const Color(0xFFf4f5f6),
                child: SafeArea(
                  left: false,
                  right: false,
                  child: _buildSectionList(context, controller),
                ),
              ),
            ));
  }

  Widget _buildSectionList(
      BuildContext context, EditProfileController controller) {
    return ListView(
      shrinkWrap: true,
      children: [
        SettingSectionItem(
            title: "头像",
            rightWidget: Container(
              alignment: Alignment.centerLeft,
              child: Container(
                  alignment: Alignment.centerLeft,
                  width: 60.w,
                  height: 60.h,
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    border: Border.all(
                      color: const Color(0x33000000),
                      width: 2.r,
                    ),
                    image: DecorationImage(
                      fit: BoxFit.fill,
                      image: NetworkImage(
                        (controller.avatar ?? ""),
                      ),
                    ),
                  )),
            ),
            onTap: () {
              Get.bottomSheet(actionSheet(controller));
            }),
        SettingSectionItem(
          title: "昵称",
          rightWidget: Text(
            controller.username ?? "",
            style: TextStyle(
              fontSize: 32.sp,
              color: const Color(0xFF999999),
            ),
          ),
          onTap: () {
            Get.to(const EditNickname());
          },
        )
      ],
    );
  }

  Widget actionSheet(EditProfileController controller) {
    return CustomDialog.customCupertinoActionSheet([
      CupertinoActionSheetActionModel("拍照", () {
        controller.takePhoto();
      }),
      CupertinoActionSheetActionModel("从相册上传", () {
        controller.selectImage();
      }),
    ]);
  }
}
